/*
 * Copyright 2019 Zhongan.com All right reserved. This software is the
 * confidential and proprietary information of Zhongan.com ("Confidential
 * Information"). You shall not disclose such Confidential Information and shall
 * use it only in accordance with the terms of the license agreement you entered
 * into with Zhongan.com.
 */

package com.zhongan.cloud.gateway.route;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 重定向Route
 *
 * @author tongyufu
 * @since 2019年6月3日 下午4:46:20
 */
@Configuration
public class ForwardRoute {

    //@Bean
    public RouteLocator forwardRouteLocator(RouteLocatorBuilder builder) {
        System.out.println("===forwardRouteLocator===");
        return builder.routes()
                .route(r -> r.path("/v2/**").filters(filter -> filter.prefixPath("/v2").changeRequestUri((exchange) -> {
                    System.out.println("=====changeRequestUri======");
                    return null;
                })).uri("http://localhost:8080/health"))
                .build();
    }

    @Bean
    public RouteLocator forwardRouteLocator2(RouteLocatorBuilder builder) {
        System.out.println("===forwardRouteLocator2===");
        return builder.routes()
                .route(r -> r.path("/v2/**").uri("http://localhost:8080/health"))
                .build();
    }
}
